import { LoadingOutlined } from '@ant-design/icons';
import { ProCard } from '@ant-design/pro-components';
import { Button, Result } from 'antd';
import type { ReactNode } from 'react';

export default (props: {
  loading: boolean;
  action?: () => void;
  actionText?: ReactNode;
  loadingText?: ReactNode;
  failText?: ReactNode;
}) => {
  const {
    loading,
    action = () => {},
    actionText = '返回',
    loadingText = '加载中...',
    failText = '加载失败',
  } = props;
  return (
    <ProCard>
      {loading ? (
        <Result title={loadingText} icon={<LoadingOutlined spin />} />
      ) : (
        <Result
          title={failText}
          status="error"
          extra={
            <Button type="primary" onClick={action} style={{ fontWeight: 'bold' }}>
              {actionText}
            </Button>
          }
        />
      )}
    </ProCard>
  );
};
